<template>
	<view style="min-height: 100%;">
		<view class="container">
			<view class="header" style="background: #2577f5">
				<view v-if="!isuser">
					<view class="pic">
						<image src="/static/imgs/icon/male1.png"></image>
						<view class="userinfo foSi30" @click.stop="toPerLogin">登录/注册</view>
					</view>
				</view>

				<view v-if="isuser">
					<view class="pic">
						<image :src="userinfo.avatarUrl"></image>
						<view class="userinfo">
							<view>{{ userinfo.nickname }}</view>
							<view><!-- 账户余额: ￥{{moneyrecordinfo.totalmoney}} --></view>
						</view>
					</view>
				</view>

				<view class="mymoney">
					<view class="item_line" @tap="toMyFind" data-id="1">
						<view>{{ noticenotecount || '0' }}</view>
						<view>面试通知</view>
					</view>

					<view class="item_line" @tap="toMyFind" data-id="-1">
						<view>{{ sendnotecount || '0' }}</view>
						<view>投递记录</view>
					</view>

					<view class="item_line" @tap="toMatchNote">
						<view>0</view>
						<view>职位匹配</view>
					</view>
				</view>

				<view class="role" @tap="bindGetUserInfo">完善资料</view>
			</view>
<!-- 
			<view class="noteoper">
				<view class="item_note" @tap="toAgentcenter">
					<view>
						<image src="/static/imgs/icon/backtop.png"></image>
					</view>
					<view class="item_title">
						<view>经纪人中心</view>
						<view>助力推广,高佣回报</view>
					</view>
				</view>

				<view class="item_note" @tap="toLogin">
					<view>
						<image src="/static/imgs/icon/gz.png"></image>
					</view>
					<view class="item_title">
						<view>企业中心</view>
						<view>免费发布,一键招聘</view>
					</view>
				</view>
			</view> -->

			<view class="navlist">
				<view class="item" @tap="toMymoney">
					<image src="/static/imgs/icon/03.png"></image>
					<view>我的钱包</view>
				</view>

				<view class="item" @tap="toSysmsg">
					<view class="tipmsg" v-if="sysmsgcount > 0">{{ sysmsgcount }}</view>
					<image src="/static/imgs/icon/ask.png"></image>
					<view>消息中心</view>
				</view>
				<view class="item" @tap="toMylooknote">
					<image src="/static/imgs/icon/footer.png"></image>
					<view>对我感兴趣</view>
				</view>

				<view class="item" @tap="refreshNotice">
					<image src="/static/imgs/icon/refresh.png"></image>
					<view>刷新简历</view>
				</view>
			</view>

			<view class="list">
				<view class="item" @tap="toMyNote">
					<image src="/static/imgs/icon/msgorder.png"></image>
					<view style="margin-left: 16rpx; margin-top: 5rpx">我的简历</view>
				</view>

				<!-- <view class="item" @tap="toMyFind" data-id="-1">
					<image src="/static/imgs/icon/matchorder.png"></image>
					<view style="margin-left: 16rpx; margin-top: 5rpx">求职管理</view>
				</view> -->

				<view class="item" @tap="toMyGz" data-id="-1">
					<image src="/static/imgs/icon/gz.png"></image>
					<view style="margin-left: 16rpx; margin-top: 5rpx">我的关注</view>
				</view>

				<!-- <view class="item" @tap="toMyComment">
					<image src="/static/imgs/icon/ask.png"></image>
					<view style="margin-left: 16rpx; margin-top: 5rpx">我的评论</view>
				</view> -->

				<view class="item" @tap="toPoints">
					<image src="/static/imgs/icon/save.png"></image>
					<view style="margin-left: 16rpx; margin-top: 5rpx">积分商城</view>
				</view>

				<view class="item" @tap="toMySave">
					<image src="/static/imgs/icon/save.png"></image>
					<view style="margin-left: 16rpx; margin-top: 5rpx">收藏夹</view>
				</view>

				<view class="item" @tap="toExtend">
					<image src="/static/imgs/icon/save.png"></image>
					<view style="margin-left: 16rpx; margin-top: 5rpx">我的推广</view>
				</view>

				<view class="item" @tap="toHelp">
					<image src="/static/imgs/icon/qorder.png"></image>
					<view style="margin-left: 16rpx; margin-top: 5rpx">帮助中心</view>
				</view>
			</view>
			<view v-if="isuser" class="list">
				<view class="item disJuC" @tap="tuLogin">
					<view style="margin-left: 16rpx; margin-top: 5rpx">退出登录</view>
				</view>
			</view>
		</view>
		<view class="cu-bar tabbar foot bg-white">
			<view class="action text-gray" @tap="toIndex">
				<view class="cuIcon-homefill"></view>
				首页
			</view>
			<view class="action text-gray" @tap="toFindjob">
				<view class="cuIcon-similar"></view>
				职位
			</view>
			<!-- <view class="action text-gray add-action" @tap="toMyinvate">
				<button class="cu-btn cuIcon-add bg-blue"></button>
				发布
			</view> -->
			<view class="action text-gray" @tap="toSysmsg">
			    <view class="cuIcon-notice"></view>
			    消息
			</view>
			<view class="action text-blue" @tap="toMyuser">
			    <view class="cuIcon-my"></view>
			    我的
			</view>
		</view>
	</view>
</template>

<script>
	// pages/user/index.js
	import {
		Token
	} from '../../utils/token.js';
	import {
		My
	} from '../my/my-model.js';
	var my = new My();
	import {
		Agent
	} from '../../model/agent-model.js';
	var agent = new Agent();
	import {
		Note
	} from '../findworker/note-model.js';
	var note = new Note(); //实例化 首页 对象

	import {
		User
	} from '../../model/user-model.js';
	var user = new User();
	import {
		Sysmsg
	} from '../../model/sysmsg-model.js';
	var sysmsg = new Sysmsg();
	import {
		Company
	} from '../../model/company-model.js';
	var company = new Company();
	export default {
		data() {
			return {
				isuser: true,
				sendnotecount: '',
				noticenotecount: '',
				totallooknum: '',
				sysmsgcount: '',
				userinfo: {
					nickName: '',
					avatarUrl: '',
					nickname: ''
				},
				istel: '',
				moneyrecordinfo: {
					totalmoney: ''
				}
			};
		}
		/**
		 * 生命周期函数--监听页面加载
		 */
		,
		onLoad: function(options) {
			this.onLoadClone3389(options);
		},
		/**
		 * 生命周期函数--监听页面初次渲染完成
		 */
		onReady: function() {},
		/**
		 * 生命周期函数--监听页面显示
		 */
		onShow: function() {
			var that = this;
			that.onLoadClone3389({});
		},
		/**
		 * 生命周期函数--监听页面隐藏
		 */
		onHide: function() {},
		/**
		 * 生命周期函数--监听页面卸载
		 */
		onUnload: function() {},
		/**
		 * 页面相关事件处理函数--监听用户下拉动作
		 */
		onPullDownRefresh: function() {
			uni.showNavigationBarLoading();
			this.onLoadClone3389({});
		},
		/**
		 * 页面上拉触底事件的处理函数
		 */
		onReachBottom: function() {},
		/**
		 * 用户点击右上角分享
		 */
		onShareAppMessage: function() {
			var that = this;
			return {
				title: '会员中心',
				path: '/pages/user/index'
			};
		},
		methods: {
			/**
			 * 生命周期函数--监听页面加载
			 */
			onLoadClone3389: function(options) {
				var that = this;
				uni.setNavigationBarTitle({
					title: '会员中心'
				});
				var appuser = uni.getStorageSync('userInfo');
				console.log('ffffffffffffffffff');
				var params = {};
				my.UserInit((data) => {
					that.setData({
						sendnotecount: data.sendnotecount,
						noticenotecount: data.noticenotecount,
						totallooknum: data.totallooknum,
						sysmsgcount: data.sysmsgcount,
						isuser: data.isuser
					});
					if (data.cdoe !== -1) {
						that.setData({
							userinfo: data.userinfo
						});
					}
					uni.hideNavigationBarLoading(); //完成停止加载
					uni.stopPullDownRefresh();
				}, params);
				// that.setData({
				// 	userinfo: appuser
				// });
				that.setData({
					isuser: that.isuser
				});
			},

			toIndex: function() {
				uni.redirectTo({
					url: '/pages/index/index'
				});
			},

			toFindjob: function(e) {
				var that = this;
				uni.redirectTo({
					url: '/pages/findjob/index'
				});
			},

			toMyinvate: function(e) {
				var that = this;
				uni.redirectTo({
					url: '/pages/switchrole/index'
				});
			},

			toSysmsg: function() {
				uni.redirectTo({
					url: '/pages/sysmsg/index'
				});
			},

			toMyuser: function() {
				uni.redirectTo({
					url: '/pages/user/index'
				});
			},

			toMymoney: function() {
				var that = this;
				if (this.isuser) {
					uni.navigateTo({
						url: '/pages/mymoney/index'
					});
				} else {
					this.toPerLogin()
				}
			},

			toLogin: function(e) {
				var that = this;
				var ctoken = uni.getStorageSync('ctoken');
				if (ctoken) {
					var params = {
						ctoken: ctoken
					};
					user.checkBind((data) => {
						if (data.isbind) {
							company.checkLogin((data) => {
								if (data.error == 0) {
									uni.navigateTo({
										url: '/pages/companycenter/index'
									});
								} else {
									uni.navigateTo({
										url: '/pages/companylogin/index'
									});
								}
							}, params);
						} else {
							this.toPerLogin()
						}
					}, params);
				} else {
					uni.navigateTo({
						url: '/pages/companylogin/index'
					});
				}
			},

			toMatchNote: function() {
				var that = this;
				if (this.isuser) {
					var params = {};
					note.CheckNote((data) => {
						if (data.status == 1) {
							uni.navigateTo({
								url: '/pages/matchjob/index'
							});
						} else if (data.status == 2) {
							uni.navigateTo({
								url: '/pages/mynote/index'
							});
						} else {
							uni.showToast({
								title: data.msg,
								icon: 'none',
								duration: 2000
							});
						}
						console.log(data);
					}, params);
				} else {
					this.toPerLogin()
				}
			},

			refreshNotice: function() {
				var that = this;
				var params = {};
				var that = this;
				var params = {};
				user.checkBind((data) => {
					if (data.isbind) {
						note.NoteRefresh((data) => {
							if (data.status == 1) {
								uni.showToast({
									title: data.msg,
									icon: 'none',
									duration: 2000
								});
							} else if (data.status == 2) {
								uni.navigateTo({
									url: '/pages/mynote/index'
								});
							} else {
								uni.showToast({
									title: data.msg,
									icon: 'none',
									duration: 2000
								});
							}
							console.log(data);
						}, params);
					} else {
						this.toPerLogin()
					}
				}, params);
			},
			toPerLogin: function() {
				var that = this;
				uni.navigateTo({
					url: '/pages/login/index'
				});
			},
			bindGetUserInfo: function() {
				var that = this;
				if (this.isuser) {
					uni.navigateTo({
						url: '/pages/bindwx/index'
					});
				} else {
					this.toPerLogin()
				}
			},

			updateuserinfo: function() {
				var that = this;
				var userinfo = uni.getStorageSync('userInfo');
				var params = {
					nickname: userinfo.nickName,
					avatarUrl: userinfo.avatarUrl
				};
				user.Updateuser((data) => {
					that.istel = data.istel;
					that.setData({
						istel: that.istel
					});
				}, params);
			},

			toAgentcenter: function() {
				var that = this;
				var params = {};
				agent.Checkagent((data) => {
					if (data.status == 0) {
						uni.navigateTo({
							url: '/pages/regagent/index'
						});
					} else if (data.status == 1) {
						uni.navigateTo({
							url: '/pages/agentcenter/index'
						});
					} else {
						uni.showModal({
							title: '提示',
							content: data.msg,
							showCancel: false
						});
						return;
					}
				}, params);
			},

			toMydone: function() {
				var that = this;
				if (this.isuser) {
					uni.navigateTo({
						url: '/pages/mydone/index'
					});
				} else {
					this.toPerLogin()
				}
			},
			tuLogin(){
				uni.removeStorageSync('token');
				uni.removeStorageSync('userInfo');
				this.onLoadClone3389({});
			},
			toHelp: function() {
				var that = this;
				if (this.isuser) {
					uni.navigateTo({
						url: '/pages/article/index?id=846'
					});
				} else {
					this.toPerLogin()
				}
			},

			toMyComment: function() {
				var that = this;
				if (this.isuser) {
					uni.navigateTo({
						url: '/pages/mycomment/index'
					});
				} else {
					this.toPerLogin()
				}
			},

			toMylooknote: function() {
				var that = this;
				if (this.isuser) {
					uni.navigateTo({
						url: '/pages/mylooknote/index'
					});
				} else {
					this.toPerLogin()
				}
			},

			toMyNote: function() {
				var that = this;
				if (this.isuser) {
					uni.navigateTo({
						url: '/pages/mynote/index'
					});
				} else {
					this.toPerLogin()
				}
			},

			toMyFind: function(e) {
				var that = this;
				if (this.isuser) {
					var id = e.currentTarget.dataset.id;
					uni.navigateTo({
						url: '/pages/myfind/index?id=' + id
					});
				} else {
					this.toPerLogin()
				}
			},

			toLookrole: function() {
				var that = this;
				if (this.isuser) {
					uni.navigateTo({
						url: '/pages/lookrole/index'
					});
				} else {
					this.toPerLogin()
				}
			},

			toMymoneyrecord: function() {
				var that = this;
				if (this.isuser) {
					uni.navigateTo({
						url: '/pages/mymoneyrecord/index'
					});
				} else {
					this.toPerLogin()
				}
			},
			toExtend: function() {
				var that = this;
				if (this.isuser) {
					uni.navigateTo({
						url: '/pages/user/extend'
					});
				} else {
					this.toPerLogin()
				}
			},
			toMySave: function(e) {
				var that = this;
				if (this.isuser) {
					uni.navigateTo({
						url: '/pages/mysave/index'
					});
				} else {
					this.toPerLogin()
				}
			},

			toPoints: function(e) {
				var that = this;
				
				if (this.isuser) {
					uni.navigateTo({
						url: '/pages/user/points'
					});
				} else {
					this.toPerLogin()
				}
			},

			toMyGz: function(e) {
				var that = this;
				if (this.isuser) {
					uni.navigateTo({
						url: '/pages/mygz/index'
					});
				} else {
					this.toPerLogin()
				}
				
			}
		}
	};
</script>
<style>
	page {
		background: #f5f5f5;
	}

	.container {
		background-color: #f5f5f5;
		min-height: 100%;
		display: flex;
		flex-direction: column;
		align-items: center;
		padding-bottom: 250rpx;
	}

	.container .header {
		width: 100%;
		height: 500rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
	}

	.role {
		position: absolute;
		width: 180rpx;
		text-align: center;
		height: 60rpx;
		line-height: 60rpx;
		background: #fca35a;
		color: #fff;
		border-radius: 25rpx 0 0 25rpx;
		left: 572rpx;
		font-size: 0.7rem;
		top: 30rpx;
	}

	.container .header .pic {
		width: 100%;
		height: 250rpx;
		align-self: center;
		display: flex;
		flex-direction: row;
		align-items: center;
		padding-left: 20rpx;
	}

	.container .header .pic image {
		width: 120rpx;
		height: 120rpx;
		border: 0rpx solid #fff;
		border-radius: 120rpx;
	}

	.container .header .pic .userinfo {
		height: 110rpx;
		width: 580rpx;
		font-size: 0.8rem;
		margin-left: 15rpx;
		color: #fff;
		display: flex;
		align-items: center;
	}

	.mymoney {
		width: 700rpx;
		display: flex;
		flex-direction: row;
		justify-content: space-around;
		background: #2577f5;
		font-size: 0.7rem;
	}

	.mymoney .item_line {
		width: 170rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		padding-top: 20rpx;
		padding-bottom: 20rpx;
		color: #fff;
		font-size: 14px;
	}

	.mymoney .item_line view:nth-child(1) {
		font-size: 18px;
		font-weight: bold;
	}

	.noteoper {
		width: 700rpx;
		background: #fff;
		height: 200rpx;
		border-radius: 25rpx;
		margin-top: -80rpx;
		display: flex;
		flex-direction: row;
		justify-content: center;
		align-items: center;
	}

	.noteoper .item_note {
		display: flex;
		flex-direction: row;
		width: 350rpx;
		justify-content: center;
	}

	.noteoper .item_note view:nth-child(1) {
		margin-right: 8rpx;
	}

	.item_note image {
		width: 80rpx;
		height: 80rpx;
	}

	.item_title {
		display: flex;
		flex-direction: column;
	}

	.item_title view:nth-child(1) {
		font-size: 14px;
		font-weight: bold;
	}

	.item_title view:nth-child(2) {
		font-size: 12px;
		color: #a2a2a2;
	}

	.advone image {
		width: 700rpx;
		height: 230rpx;
		margin-top: 20rpx;
	}

	.navlist {
		margin-top: -80rpx;
		width: 700rpx;
		display: flex;
		justify-content: space-around;
		flex-direction: row;
		padding-top: 20rpx;
		flex-wrap: wrap;
		background: #fff;
		border-radius: 25rpx;
		margin-top: -80rpx;
		height: 220rpx;
		align-items: center;
	}

	.navlist .item {
		width: 130rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		font-size: 0.7rem;
		padding-bottom: 30rpx;
		position: relative;
	}

	.tipmsg {
		background: red;
		color: #fff;
		width: 35rpx;
		height: 35rpx;
		border-radius: 50%;
		display: flex;
		justify-content: center;
		align-items: center;
		/*
  padding:8rpx;
  border-radius: 100%;
  */
		position: absolute;
		top: -12rpx;
		left: 80rpx;
		z-index: 1000;

		font-size: 0.7rem;
	}

	.navlist .item image {
		width: 80rpx;
		height: 80rpx;
	}

	.container .list {
		width: 700rpx;
		margin-top: 20rpx;
		margin-bottom: 20rpx;
		background: #fff;
		border-radius: 25rpx;
	}

	.container .list .item {
		padding-top: 35rpx;
		padding-bottom: 35rpx;
		font-size: 14px;
		border-bottom: 0rpx solid #efefef;
		padding-left: 20rpx;
		color: #747474;
		display: flex;
		flex-direction: row;
	}

	.container .list .item image {
		width: 55rpx;
		height: 55rpx;
		margin-right: 10rpx;
	}
</style>